/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __LIB3D_VELOCITYEVENT_H__
#define __LIB3D_VELOCITYEVENT_H__

#include <xml/Object.h>
#include <xml/Stream.h>
#include "../ParticleEvent.h"
#include <lib3d/Math_lib3d.h>

namespace liba
{
	namespace lib3d
	{
		namespace particles
		{
			class VelocityEvent : public ParticleEvent
			{
			private:
				struct VelocityRandom
				{
					math::Vector3<Float> value;
					Matrix               random;
					math::Vector3<Float> random2;
					bool                 useRotate;
				};
			private:
				bool                 _affectedByRotation;
				Float                _time;
				bool                 _relative;
				math::Vector3<Float> _velocity;
				bool                 _randomUsed;
				math::Vector3<Float> _randomMin;
				math::Vector3<Float> _randomMax;
				bool                 _useRotate;
			private:
				virtual ~VelocityEvent();
				VelocityRandom * get_random_for_particle(Particle * particle);
				math::Vector3<Float> get_velocity_for_particle(Particle * particle, KeyFrameIterator base_frame, KeyFrameArray * frames);
			public:
				VelocityEvent();
				void set_velocity(const math::Vector3<Float> & velocity);
				void set_time(float value);
				math::Vector3<Float> get_velocity();
				virtual void update_particle(Particle * particle, Float delta_time, KeyFrameIterator base_frame, KeyFrameIterator next_frame, KeyFrameArray * frames);
				virtual Atom get_type();
				virtual Float get_time();
				virtual bool on_attribute(xml::Provider * provider, const std::string & name, const std::string & value);
				virtual void on_save_attributes(xml::SaverBase * saver) const;
			};
		}
	}
}

#endif